package com.itheima.day07.myCollection.test1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

public class Test {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
//        boolean add(E e)                    向集合中添加元素
        collection.add("aaa");
        collection.add("bbb");
        collection.add("b");
        collection.add("aa");
        collection.add("bb");
        collection.add("ccc");
        collection.add("c");
        collection.add("a");
        collection.add("cc");
        System.out.println(collection);

//        boolean remove(E e)              将元素从集合中删除
//        collection.remove("a");
//        System.out.println(collection);

//        boolean removeIf(Object o)   根据条件进行删除
        collection.removeIf(new Predicate<String>() {
                                @Override
                                public boolean test(String s) {
                                    if(s.length() == 3 || s.length() == 2){
                                        return true;
                                    }
                                    return false;
                                }
                            }
        );
        System.out.println(collection);


//        void clear()                              清空集合所有的元素
//        collection.clear();
//        System.out.println(collection);

//        boolean contains(E e)             判断集合中是否包含指定的元素
        boolean contains1 = collection.contains("a");
        boolean contains2 = collection.contains("d");
        System.out.println(contains1);
        System.out.println(contains2);

//        boolean isEmpty()                   判断集合是否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);

//        int size()                                   获取集合的长度
        int size = collection.size();
        System.out.println(size);

    }
}
